package com.leetcode.partition4;

/**
 * @author `RKC`
 * @date 2021/10/29 8:38
 */
public class LC335路径交叉 {

    public static boolean isSelfCrossing(int[] distance) {
        for (int i = 3; i < distance.length; i++) {
            //第一类交叉情况
            if (distance[i] >= distance[i - 2] && distance[i - 1] <= distance[i - 3]) return true;
            //第二类交叉情况
            if (i == 4 && (distance[3] == distance[1] && distance[4] >= distance[2] - distance[0])) return true;
            //第三类交叉情况
            if (i >= 5 && (distance[i - 1] >= distance[i - 3] - distance[i - 5]
                    && distance[i - 1] <= distance[i - 3]
                    && distance[i] >= distance[i - 2] - distance[i - 4]
                    && distance[i - 2] > distance[i - 4])) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(isSelfCrossing(new int[]{2, 1, 1, 2}));
        System.out.println(isSelfCrossing(new int[]{1, 1, 2, 1, 1}));
    }
}
